package me.ingxin.android.permission2.view.impl

import android.content.Context
import me.ingxin.android.permission2.view.Guide
import me.ingxin.android.permission2.view.GuideView

/**
 * Created on 2023/7/22 by yin
 */
internal class SimpleGuide(
    private val tipsBlock: ((List<String>) -> CharSequence?)?,
    private val reasonBlock: ((List<String>, Boolean) -> CharSequence?)?
) : Guide() {

    override fun createReasonView(context: Context, permissions: List<String>): GuideView =
        MyReasonView(context, permissions, false, reasonBlock)

    override fun createToSettingsView(context: Context, permissions: List<String>): GuideView =
        MyReasonView(context, permissions, true, reasonBlock)

    override fun createTipsView(context: Context, permissions: List<String>): GuideView =
        MyTipsView(context, permissions, tipsBlock)

    private class MyTipsView(
        context: Context,
        permissions: List<String>,
        private val block: ((List<String>) -> CharSequence?)?
    ) : DefaultTipsDialog(context, permissions) {
        override fun getMessage(permissions: List<String>): CharSequence? {
            return block?.invoke(permissions)
        }
    }

    private class MyReasonView(
        context: Context,
        permissions: List<String>,
        toSettings: Boolean,
        private val block: ((List<String>, Boolean) -> CharSequence?)?
    ) : DefaultReasonDialog(context, permissions, toSettings) {
        override fun getMessage(permissions: List<String>, toSettings: Boolean): CharSequence? {
            return block?.invoke(permissions, toSettings)
        }
    }


}